package com.nebula.core.jdbc;

import java.sql.SQLException;
import java.sql.Wrapper;

/**
 * @author admin
 */

public interface BaseWrapper extends Wrapper {

    @Override
    default <T> T unwrap(Class<T> iface) throws SQLException {
        if (isWrapperFor(iface)) {
            return (T) this;
        }
        throw new SQLException(String.format("The object: [%s] can not implement the interface: [%s]", this, iface));
    }

    @Override
    default boolean isWrapperFor(Class<?> iface) throws SQLException {
        return iface.isAssignableFrom(this.getClass());
    }
}
